package day01;

import java.io.*;

/**
 * @author feng
 * @Date 2021/12/27 10:12
 * 二进制流拷贝
 */
public class BufferInput {
    public static void main(String[] args) {
        String source = "D:\\IO\\1.png";
        String dest = "D:\\IO\\A\\B\\1.png";
        BufferedInputStream bufferedInputStream = null;
        BufferedOutputStream bufferedOutputStream = null;
        byte[] bytes = new byte[8];
        int count = 0;
        try {
            bufferedInputStream = new BufferedInputStream(new FileInputStream(source));
            bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(dest));
            while ((count = bufferedInputStream.read(bytes)) != -1) {
                bufferedOutputStream.write(bytes,0,count);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //理解:管道里边没东西，当有东西，写入了
            try {
                if (bufferedInputStream != null) {
                    bufferedInputStream.close();
                }
                if (bufferedOutputStream != null) {
                    bufferedInputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
